package com.tian.view.touch.dispatch

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import androidx.appcompat.widget.AppCompatButton

/**
 * @author tiansongtao
 * @date 2023/1/10 17:27
 */
class CustomChildView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :
        AppCompatButton(context, attrs, defStyleAttr) {

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context) : this(context, null)

    private val TAG = "tiansongtao"

    var moveIntercept = false

    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
        Log.i(TAG, "CustomChildView dispatchTouchEvent: MotionEvent.action=${ev?.action}")
        return super.dispatchTouchEvent(ev)
    }



    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(event: MotionEvent): Boolean {
        Log.i(TAG, "CustomChildView onTouchEvent: MotionEvent.action=${event.action}")
        if (event.action == MotionEvent.ACTION_DOWN &&  moveIntercept) {
            return true
        }
        return super.onTouchEvent(event)
    }
}